package com.zhangdi.demo.es.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zhangdi on 2021/01/29 20:05:09.
 */
public class DateUtils {
    public static Date parse(String str){
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return df.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static String formatFromString(String str){
        if(StringUtils.isEmptyNone(str)){
            return "";
        }
        return formatExact(parse(str));
    }

    public static String formatExact(Date date){
        if (date == null) {
            return "";
        }
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }
}
